/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cliente.servidor;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 *
 * @author lisafbe
 */

  public class Atiende extends Thread{
   	private BufferedReader entrada;
   	private DataOutputStream salida;
   	private String llego;
   	private Socket cliente = null;
   	private String nombreyDirIP;

 	public Atiende(Socket cliente){
   		this.cliente = cliente;
   		nombreyDirIP = this.cliente.getInetAddress().toString();
   	}

 	public void run(){
   		try{
   			Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
  			 entrada = new BufferedReader(new InputStreamReader(cliente.getInputStream()));
   			salida = new DataOutputStream(cliente.getOutputStream());

 			do{
   				llego = entrada.readLine();
   				System.out.println("("+nombreyDirIP+") Llego: " + llego);
   				salida.writeInt(llego.length());
   			}while(llego.length()!=0);

 			entrada.close();
   			cliente.close();
   		}catch(IOException e){
   			System.out.println(e.getMessage());
   			System.exit(1);
   		}
   			System.out.println("Ya se desconecto"+"("+nombreyDirIP+")");
	} 
}
